package net.sunofbeach.blog.controller.admin;


import net.sunofbeach.blog.interceptor.CheckTooFrequentCommit;
import net.sunofbeach.blog.response.ResponseResult;
import net.sunofbeach.blog.services.IPdfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/pdf")
public class PdfAdminApi {


    @Autowired
    private IPdfService pdfService;

    @CheckTooFrequentCommit
    @PreAuthorize("@permission.admin()")
    @PostMapping()
    public  ResponseResult cosuploadPdf(@RequestParam("file") MultipartFile file){
        return pdfService.cosUploadPdf(file);
    }

    @PreAuthorize("@permission.admin()")
    @GetMapping("/list/{page}/{size}")
    public ResponseResult listPdfs(@PathVariable("page") int page,
                                     @PathVariable("size") int size){
        return pdfService.listPdfs(page,size);
    }

}
